home *** CD-ROM | disk | FTP | other *** search
- #ifndef CLIPPINGWINDOW_H
- #include "ClippingWindow.h"
- #endif
-
- #ifndef CLIPPINGFILEDATA_H
- #include "ClippingFileData.h"
- #endif
-
- #ifndef CLIPPINGFILE_H
- #include "ClippingFile.h"
- #endif
-
- #ifndef FLOATERS_H
- #include "Floaters.h"
- #endif
-
- #ifndef THUMBNAIL_H
- #include "Thumbnail.h"
- #endif
-
- #define kLeftWindowProc 3201 // No drag bar
- #define kRightWindowProc 3200 // No drag bar
-
- CClippingWindow::CClippingWindow (CClippingFile* theFile) :
- fClippingFile (theFile),
- fThumbnail (nil)
- {
- CClippingFileData* theData = theFile -> GetData ();
- Boolean onLeft = theData -> GetOnLeft ();
-
- Rect bounds = CalculateWindowBounds (onLeft, theData -> GetOffset ());
- fThumbnail = theFile -> GetThumbnail ();
- if (!fThumbnail)
- fThumbnail = CThumbnail::NewThumbnail (fClippingFile, bounds);
-
- fWindow = NewFloater (nil, &bounds, "\p", false,
- onLeft ? kLeftWindowProc : kRightWindowProc, (WindowPtr) -1, false, (long) this, 0,
- CClippingWindow::EventProc, CClippingWindow::ClippingDisposeProc);
- if (!fWindow)
- throw memFullErr;
-
- // ••• Reference the prefereces file for this information
- Handle wctb = GetResource ('wctb', 128 + (Random () & 0x7FFF) % 6);
- if (wctb)
- SetWinColor (fWindow, (WinCTab**)wctb);
-
- ShowWindow (fWindow);
- UpdateFloater (fWindow);
- }
-
- void CClippingWindow::ClippingDisposeProc (WindowPtr win)
- {
- try {
- delete ((CClippingWindow*) GetWRefCon (win));
- } catch (...) {
- }
- }
-
- void CClippingWindow::EventProc (EventRecord *theEvent, WindowPtr win)
- {
- CClippingWindow* that = (CClippingWindow*) GetWRefCon (win);
- if (!that)
- return;
-
- try {
-
- switch (theEvent -> what) {
-
- case updateEvt :
- GrafPtr oldPort;
-
- GetPort (&oldPort);
- SetPort (win);
- Rect r = win -> portRect;
- InsetRect (&r, 6, 2);
-
- BeginUpdate (win);
- EraseRect (&win -> portRect);
- that -> fThumbnail -> Draw (r);
- EndUpdate (win);
- break;
- }
- } catch (...) {
- }
- }
-
- CClippingWindow::~CClippingWindow ()
- {
- try {
- DisposeFloater (fWindow);
- delete fThumbnail;
- delete fClippingFile;
- } catch (...) {
- }
- }
-
- void CClippingWindow::RePositionWindow ()
- {
- }
-
- Rect CClippingWindow::CalculateWindowBounds (Boolean onLeft, short offset)
- {
- Rect screen = (**GetGrayRgn ()).rgnBBox;
- Rect bounds = { 0, 0, 20, 80 };
-
- if (onLeft) {
- OffsetRect (&bounds, screen.left, offset);
- } else {
- OffsetRect (&bounds, screen.right - (bounds.right - bounds.left), offset);
- }
-
- return bounds;
- }
-